package org.xm.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xm.model.Item;
import org.xm.model.Order;
import org.xm.model.Warehouse;
import org.xm.service.WarehouseService;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/api")
public class WarehouseController {
    @Autowired
    private WarehouseService warehouseService;

    @GetMapping("/warehouses")
    public List<Warehouse> getAllWarehouses() {
        return warehouseService.getAllWarehouses();
    }

    @GetMapping("/warehouses/{warehouseId}/items")
    public List<Item> getItemsByWarehouseId(@PathVariable Long warehouseId) {
        return warehouseService.getItemsByWarehouseId(warehouseId);
    }

    @GetMapping("/orders")
    public List<Order> getAllOrders() {
        return warehouseService.getAllOrders();
    }

    @PostMapping("/add-warehouse")
    public void addWarehouse(@RequestBody Warehouse warehouse) {
        log.info("[addWarehouse]:warehouse:{} ", warehouse);
        warehouseService.addWarehouse(warehouse);
    }

    @PostMapping("/add-item")
    public void addItem(@RequestBody Item item) {
        log.info("[addItem]:item:{} ", item);
        warehouseService.addItem(item);
    }
}